convert hex rgb to matplotlib color

39

hex_color = '3366CC'

# from 0-255 integer format
up_to_255_rgb = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
#output: (51, 102, 204)

# from 0-1 float format
up_to_1_rgb = tuple(int(hex_color[i:i+2], 16)/255 for i in (0, 2, 4))
#output: (0.2, 0.4, 0.8)

Comments

Submit
0 Comments